import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;


public class GameRunner {

    private GameBoard gameBoard;
    private Player player1;
    private Player player2;

    public GameRunner(GameBoard gameBoard, Player player1, Player player2) {
        this.gameBoard = gameBoard;
        this.player1 = player1;
        this.player2 = player2;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        PrintStream printStream = System.out;

        List<String> positionList = new ArrayList<String>();
        for (int i = 0; i < 9; i++) {
            positionList.add("   ");
        }

        GameBoard gameBoard1 = new GameBoard(positionList);

        ValidInputGetter validInputGetter = new ValidInputGetter(printStream, bufferedReader, gameBoard1);

        Player player1 = new Player(" x ", gameBoard1, validInputGetter);
        Player player2 = new Player(" o ", gameBoard1, validInputGetter);

        new GameRunner(gameBoard1, player1, player2).start(System.out);
    }

    public void start(PrintStream printStream) throws IOException {
        Player currentPlayer = player1;
        this.gameBoard.drawBoard(printStream);

        while(!gameBoard.isFull()){
            currentPlayer.turn();
            this.gameBoard.drawBoard(printStream);
            if (currentPlayer.equals(player1)){
                currentPlayer = player2;
            }
            else {
                currentPlayer = player1;
            }



        }

        printStream.println("Game is a draw");

    }

}
